<template>
    <div id="temp">
        <!--商品列表部分  -->
        <div id="mui-content" class="mui-content" style="background-color:#fff">
            <ul class="mui-table-view mui-grid-view">
                <li class="mui-table-view-cell mui-media mui-col-xs-6" v-for="(item,index) in goodsList" :key="index">
                    <router-link v-bind='{to:"/goods/goodsinfo/"+item.id}'>
                        <img class="mui-media-object" :src="item.img_url">
                        <div class="mui-media-body">{{item.title}}</div>
                        <div class="desc">
                            <p>
                                <span>￥{{item.market_price}}</span>
                                <s>￥{{item.sell_price}}</s>
                            </p>
                            <p>
                                <h6 class="left">热卖中</h6>
                                <h6 class="right">剩余{{item.stock_quantity}}件</h6>
                            </p>
                        </div>
                    </router-link>
                </li>
            </ul>
    
            <!--点击加载更多  -->
            <mt-button type="danger" size="large" @click="getMoreGoods" id="danger">{{more}}</mt-button>
        </div>
    
    </div>
</template>
<script>

//导入全局域名
import common from '../../kits/common.js';

//导入提示小组件
import { Toast } from 'mint-ui';

export default {
    data() {
        return {
            goodsList: [],
            more: "点击加载更多 >>",
            pageIndex: 1
        }
    },
    created() {
        this.getGoodsList(this.pageIndex);
    },
    methods: {
        getGoodsList(pageIndex) {
            this.pageIndex = pageIndex || 1;
            this.$http.get(common.urlHost + "/api/getgoods?pageindex=" + this.pageIndex)
                .then(function (res) {
                    if (res.body.status != 0) {
                        Toast({
                            message: res.body.message,
                            duration: 3000
                        });
                    }
                    this.more = res.body.message.length < 10 ? "没有更多了" : "点击加载更多 >>";
                    this.goodsList = this.goodsList.concat(res.body.message);
                })
        },
        getMoreGoods() {
            this.pageIndex++;
            this.getGoodsList(this.pageIndex);
        }
    }
}
</script>
<style scoped>
#mui-content li {
    border: 1px solid rgba(0, 0, 0, 0.4);
    -webkit-box-shadow: 0 0 4px #000;
    -moz-box-shadow: 0 0 4px #000;
    box-shadow: 0 0 4px #000;
    margin-left: 4px;
    padding-left: 0px;
}

#mui-content .mui-media-body {
    color: #0094ff;
}

#mui-content .desc {
    height: 60px;
    background-color: rgba(0, 0, 0, 0.1);
    margin-top: 10px;
    padding: 5px;
    text-align: left;
}

#mui-content .desc span {
    color: red;
    margin-right: 15px;
}

#mui-content a {
    padding-left: 0px;
    margin-left: 0px;
}

#mui-content .desc .right {
    position: absolute;
    right: 10px;
    bottom: 0px;
}

#mui-content .desc .left {
    position: absolute;
    left: 10px;
    bottom: 0px;
}
</style>


